#include <stdio.h>
#include <stdlib.h>

typedef short int bool;
#define true    1
#define false   0

#define N 1000

/*
There is exactly one node, called the root, to which no directed edges point.
Every node except the root has exactly one edge pointing to it.
There is a unique sequence of directed edges from the root to each node.
*/

short int edges[N][2] = {{0}};
short int en = 0;
short int node[N] = {-1};
short int nn = 0;


short int casecount = 0;

void init()
{
    en = 0;
    nn = 0;
}

int max(int a, int b)
{
    return a > b ? a : b;
}

int min(int a, int b)
{
    return a > b ? b : a;
}

void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int partition(short int* a,int low, int high)
{
    int pivot = a[low];
    while(low < high)
    {
        while(pivot < a[high] && high > low)
        {
            high--;
        }
        if(high > low)
        {
            a[low] = a[high];
            low++;
        }
        while(pivot > a[low] && high > low)
        {
            low++;
        }
        if(high > low)
        {
            a[high] = a[low];
            high--;
        }
    }
    a[low] = pivot;

    return low;

}

void quick_sort(short int* a, int low, int high)
{
    int pivot = 0;

    if(low < high)
    {
        pivot = partition(a, low, high);

        quick_sort(a, low, pivot-1);
        quick_sort(a, pivot+1, high);
    }

}

void delrepeat()
{
    int i = 0, k = 0, pre = 0;

    if(nn <= 1)
    {
        return;
    }

    quick_sort(&node[0], 0, nn-1);

    pre = node[0];
    for(i = 1, k = 1; i < nn; i++)
    {
        if(node[i] == pre)
        {
            continue;
        }
        else
        {
            node[k++] = node[i];
            pre = node[i];
        }
    }
    nn = k;
//    for(i = 0; i < nn; i++)
//    {
//        printf("%d ", node[i]);
//    }
//    printf("\n");
}

bool testroot()
{
    int i = 0, j = 0;
    int c = 0, root = -1;
    int beginnode = 0, curnode = 0;

    delrepeat();

    if(nn != 0 && en != nn-1)
    {
        return false;
    }

    for(i = 0; i < nn; i++)
    {
        c = 0;
        for(j = 0; j < en; j++)
        {
            if(edges[j][1] == node[i])
            {
                if(c == 0)
                {
                    c++;
                }
                else
                {
                    return false;
                }
            }
        }
    }

    for(i = 0; i < nn; i++)
    {
        curnode = beginnode = node[i];
        while(1)
        {
            for(j = 0; j < en; j++)
            {
                if(edges[j][1] == curnode)
                {
                    curnode = edges[j][0];
                    break;
                }
            }
            if(j >= en)
            {
                if(root == -1)
                {
                    root = curnode;
                }
                else if(root != curnode)
                {
                    return false;
                }
                else
                {
                    break;
                }
            }
            if(curnode == beginnode && beginnode != root)
            {
                return false;
            }
        }
    }


    return true;
}

void process()
{
    int i = 0;
    bool btree = true;

    for(i = 0; i < en; i++)
    {
        //printf("%d %d\t", edges[i][0], edges[i][1]);
        node[nn++] = edges[i][0];
        node[nn++] = edges[i][1];
    }
    //printf("\n");

    btree = testroot();


    if(btree == true)
    {
        printf("Case %d is a tree.\n", ++casecount);
    }
    else
    {
        printf("Case %d is not a tree.\n", ++casecount);
    }
}

int main()
{
    //freopen("bin\\debug\\in.txt", "r", stdin);

    int v1 = 0, v2 = 0;
    bool endflag = false;

    while(endflag == false)
    {
        scanf("%d%d", &v1, &v2);
        if(v1 == 0 && v2 == 0)
        {
            process();
            init();
        }
        else if(v1 == -1 && v2 == -1)
        {
            endflag = true;
        }
        else
        {
            edges[en][0] = v1;
            edges[en][1] = v2;
            en++;
        }
    }


    return 0;
}
